import myAxios from './myAxios.js'
import {baseURL} from '../config'
import weatherData from './weather.json'
// import jsonp from 'jsonp'

// 登录请求
export const reqLogin = (value) => myAxios.post(`${baseURL}/login`,value);

// 获取商品分类列表请求
export const reqCategoryList = () => myAxios.get(`${baseURL}/manage/category/list`);

// 获取天气请求
export const weather = () => {
  // let url = `http://t.weather.itboy.net/api/weather/city/${city_id}`
  // jsonp('http://t.weather.itboy.net/api/weather/city/101280601',{}, (err,data)=>{
  //   console.log(err,data)
  // });
  return new Promise((resolve, reject) => {
    if (weatherData) {
      resolve(weatherData)
    } else {
      reject('未获取到数据')
    }
  })
};

// 添加分类
export const reqAddCategory = (categoryName) => myAxios.post(`${baseURL}/manage/category/add`, {categoryName});

// 修改更新分类
export const reqUpdateCategory = (info) => myAxios.post(`${baseURL}/manage/category/update`, info);

// 获取商品分页列表
export const reqProductList = ({pageNum,pageSize}) => myAxios.get(`${baseURL}/manage/product/list?pageNum=${pageNum}&pageSize=${pageSize}`);

// 根据Name/desc搜索产品分页列表
export const reqSearchNameOrDesc = ({pageNum,pageSize,productNameOrDesc,searchContent}) => myAxios.get(`${baseURL}/manage/product/search/?pageNum=${pageNum}&pageSize=${pageSize}&${productNameOrDesc}=${searchContent}`);

// 对商品进行上架/下架处理
export const reqProductUpdateStatus = ({productId,status}) => myAxios.post(`${baseURL}/manage/product/updateStatus`,{productId,status});

//根据商品ID获取商品详情
export const reqProductInfo = (productId) => myAxios.get(`${baseURL}/manage/product/info?productId=${productId}`);

// 根据分类ID获取分类
export const reqCategoryInfo = (categoryId) => myAxios.get(`${baseURL}/manage/category/info?categoryId=${categoryId}`);

// 删除图片
export const reqDeleteImg = (name) => myAxios.post(`${baseURL}/manage/img/delete`, {name})

// 添加商品
export const reqAddProduct = (produceInfoObj) => myAxios.post(`${baseURL}/manage/product/add`,produceInfoObj)

// 更新商品
export const reqUpdateProduct = (produceInfoObj) => myAxios.post(`${baseURL}/manage/product/update`,produceInfoObj)

// 获取角色列表
export const reqRoleList = () => myAxios.get(`${baseURL}/manage/role/list`)

// 添加角色
export const reqAddRoles = (roleName ) => myAxios.post(`${baseURL}/manage/role/add`,{roleName})

// 更新角色(给角色设置权限)
export const reqUpdateRoles = (updateRoleObj) => myAxios.post(`${baseURL}/manage/role/update`,updateRoleObj)

// 获取所有用户列表
export const reqUserList = () => myAxios.get(`${baseURL}/manage/user/list`)

// 添加用户
export const reqAddUser = (userInfo) => myAxios.post(`${baseURL}/manage/user/add`,userInfo)

// 更新用户
export const reqUpdateUser = (userInfo) => myAxios.post(`${baseURL}/manage/user/update`,userInfo)

// 删除用户
export const reqDeleteUser = (userId) => myAxios.post(`${baseURL}/manage/user/delete`,userId)

